import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';


export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'carCostNo',
    label: '费用单号',
  },
  {
    component: 'Input',
    fieldName: 'frameNo',
    label: '车架号',
  },
  {
    component: 'Select',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.APPROVE_STATUS 便于维护
      options: getDictOptions('approve_status'),
    },
    fieldName: 'status',
    label: '状态',
  },
];

// 基础列配置
const baseColumns: VxeGridProps['columns'] = [
  {
    title: '费用单号',
    field: 'carCostNo',
    width: 160,
    slots: {
      default: 'carCostNo'
    },
  },
  {
    title: '订单号',
    field: 'orderNo',
    width: 160,
  },
  {
    title: '车架号',
    field: 'frameNo',
    width: 100,
  },
  {
    title: '客户名称',
    field: 'customerName',
    width: 120,
  },
  {
    title: '状态',
    field: 'status',
    width: 100,
    slots: {
      default: ({ row }) => {
        // 可选从DictEnum中获取 DictEnum.APPROVE_STATUS 便于维护
        return renderDict(row.status, 'approve_status');
      },
    },
  },
  {
    title: '上牌过户费',
    field: 'plateCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '检测报告费',
    field: 'checkCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '交强险',
    field: 'insuranceCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '车船税',
    field: 'vehicleTaxCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '清关费',
    field: 'clearCustomsCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '报关费',
    field: 'declarationCustomsCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '运费',
    field: 'shipCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '其他费用',
    field: 'otherCost',
    width: 100,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '其他费用名称',
    field: 'otherCostName',
    width: 120,
  },
  {
    title: '费用合计',
    field: 'totalAmount',
    width: 120,
    align: 'right',
    formatter: ({ cellValue }) => {
      return cellValue ? `¥${Number(cellValue).toFixed(2)}` : '-';
    },
  },
  {
    title: '审核人',
    field: 'approverName',
    width: 100,
  },
  {
    title: '审核时间',
    field: 'approveTime',
    width: 160,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 100,
  },
];
 

// 根据状态动态生成列配置
export const getColumns = (status?: string): VxeGridProps['columns'] => {
  const columns = [...baseColumns];
  return columns;
};

// 车辆费用状态常量
export const CAR_COST_STATUS = {
  PENDING_SUBMIT: 'PENDING_SUBMIT', // 待提交
  PENDING_REVIEW: 'PENDING_REVIEW', // 待审核
  APPROVED: 'APPROVED', // 已通过
  REJECTED: 'REJECTED', // 已驳回
  CANCELLED: 'CANCELLED', // 已作废
} as const;


// 默认列配置（保持向后兼容）
export const columns: VxeGridProps['columns'] = getColumns();

